<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class lophoc_db 
	{
		public function Them($MaLopHoc, $MaKhoaHoc, $MaChuongTrinh, $MaThoiGianHoc, $MaPhong, $PIN)
		{
			$sql = "INSERT INTO `tbl_lophoc`(`MaLopHoc`, `MaKhoaHoc`, `MaChuongTrinh`, `MaThoiGianHoc`, `MaPhong`, `PIN`)
					VALUES ('$MaLopHoc', '$MaKhoaHoc', '$MaChuongTrinh', '$MaThoiGianHoc', '$MaPhong', '$PIN')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaLopHoc)
		{
			$sql = "DELETE FROM `tbl_lophoc` WHERE `MaLopHoc` = '$MaLopHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaLopHoc, $MaKhoaHoc, $MaChuongTrinh, $MaThoiGianHoc, $MaPhong, $PIN)
		{
			$sql = "UPDATE `tbl_lophoc`
					SET `MaKhoaHoc` = '$MaKhoaHoc', `MaChuongTrinh` = '$MaChuongTrinh', `MaThoiGianHoc` = '$MaThoiGianHoc', `MaPhong` = '$MaPhong', `PIN` = '$PIN'
					WHERE `MaLopHoc` = '$MaLopHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaLopHoc, $MaKhoaHoc, $MaChuongTrinh, $MaThoiGianHoc, $MaPhong, $PIN)
		{
			$sql = "SELECT * FROM `tbl_lophoc` WHERE 1  ";
			if($MaLopHoc != "")
				$sql .= " AND `MaLopHoc` = '$MaLopHoc' ";

			if($MaKhoaHoc != "")
				$sql .= " AND `MaKhoaHoc` = '$MaKhoaHoc' ";

			if($MaChuongTrinh != "")
				$sql .= " AND `MaChuongTrinh` = '$MaChuongTrinh' ";

			if($MaThoiGianHoc != "")
				$sql .= " AND `MaThoiGianHoc` = '$MaThoiGianHoc' ";

			if($MaPhong != "")
				$sql .= " AND `MaPhong` = '$MaPhong' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

